package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {

    /*
     * 添加分类数据
     * */
    @Insert("insert into category values (null,#{type},#{name},#{sort},#{createTime},#{updateTime}," +
            "#{createUser},#{updateUser})")
    Integer save(Category category);


    /*
     * 根据类别名称查询类别
     * */
    @Select("select *from category where name=#{name} ")
    Category findByName(String name);


    /*
    * 套餐分页查询(分表查,第二条sql语句,根据类别id查询类别对象)
    * */
    @Select("select *from category where id=#{id}")
    Category findById(Long id);




    /*
     *  查询类别所有数据,根据sort字段排序
     * */
    @Select("select * from category order by  sort ASC")
    List<Category> findAll();


    /*
     * 删除指定类别
     * */
    @Delete("delete from category where id=#{id}")
    Integer deleteById(Long id);


    /*
     * 修改类别
     * */
    Integer update(Category category);

    /*
     * 查询与当前类别名称不一样的类别,排除自己类别的id
     * */
    @Select("select *from category where name =#{name} and id!=#{id}")
    Category findByName2(Category category);


    /*
    * 根据类型查询类别列表数据
    * */
    List<Category> findAllByType(@Param("type") Integer type);
}
